package com.zzl.alligator.management.monitor.controller;

import com.zzl.alligator.common.enums.BusinessTypeEnum;
import com.zzl.alligator.common.util.ExcelUtils;
import com.zzl.alligator.framework.aspectj.annotation.Log;
import com.zzl.alligator.framework.base.controller.BaseController;
import com.zzl.alligator.framework.support.web.vo.JsonResult;
import com.zzl.alligator.management.monitor.domain.SysJobLog;
import com.zzl.alligator.management.monitor.service.ISysJobLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 定时任务调度日志表(SysJobLog)控制层
 *
 * @author zhouziliang
 * @since 2020-07-11
 */
@RestController
@RequestMapping("/monitor/jobLog")
public class SysJobLogController extends BaseController {
    
    /**
     * 服务对象
     */
    @Autowired
    private ISysJobLogService sysJobLogService;

    /**
     * 分页查询所有数据
     *
     * @param sysJobLog 查询实体
     * @return 所有数据
     */
    @GetMapping
    public JsonResult findList(SysJobLog sysJobLog) {
        startPage();
        List<SysJobLog> sysJobLogList = sysJobLogService.findSysJobLogList(sysJobLog);
        return JsonResult.success(getDataTable(sysJobLogList));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param jobLogId 主键
     * @return 单条数据
     */
    @GetMapping("/{jobLogId}")
    public JsonResult findById(@PathVariable Long jobLogId) {
        return JsonResult.success(sysJobLogService.findSysJobLogById(jobLogId));
    }

    /**
     * 新增数据
     *
     * @param sysJobLog 实体对象
     * @return 新增结果
     */
    @PostMapping
    @Log(title = "新增定时任务调度日志表", businessType = BusinessTypeEnum.INSERT)
    public JsonResult add(@RequestBody SysJobLog sysJobLog) {
        return toAjax(this.sysJobLogService.insertSysJobLog(sysJobLog));
    }

    /**
     * 修改数据
     *
     * @param sysJobLog 实体对象
     * @return 修改结果
     */
    @PutMapping
    @Log(title = "更新定时任务调度日志表", businessType = BusinessTypeEnum.UPDATE)
    public JsonResult update(@RequestBody SysJobLog sysJobLog) {
        return toAjax(this.sysJobLogService.updateSysJobLog(sysJobLog));
    }

    /**
     * 删除数据
     *
     * @param jobLogId 主键
     * @return 删除结果
     */
    @DeleteMapping("/{jobLogId}")
    @Log(title = "删除定时任务调度日志表", businessType = BusinessTypeEnum.DELETE)
    public JsonResult delete(@PathVariable Long jobLogId) {
        return toAjax(this.sysJobLogService.deleteById(jobLogId));
    }
    
    /**
     * 导出数据
     * 
     * @param sysJobLog 条件
     * @return 导出文件路径
     */
    @GetMapping("/export")
    @Log(title = "导出定时任务调度日志表", businessType = BusinessTypeEnum.EXPORT)
    public JsonResult export(SysJobLog sysJobLog) {
        List<SysJobLog> list = sysJobLogService.findSysJobLogList(sysJobLog);
        ExcelUtils<SysJobLog> util = new ExcelUtils<>(SysJobLog.class);
        return util.exportExcel(list, "定时任务调度日志表数据");
    }
}